/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import com.us.usws.biz.ResourceURIReplacer;
import com.us.usws.cache.UserCache;
import com.us.usws.dao.VideoFileDAO;
import com.us.usws.model.domain.video.VideoFile;
import com.us.usws.service.ro.VideoFileROService;
import com.us.usws.support.ext.CacheManager;
import com.us.usws.support.uitls.DataPageUtil;

/**
 * Service RO impl class
 * @author robot
 */
public class VideoFileROServiceImpl implements VideoFileROService {

	/**
	 * DAO instance
	 */
	private VideoFileDAO dao = new VideoFileDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<VideoFile> getAllVideoFiles() {
		return dao.getAllVideoFiles();
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<VideoFile> getVideoFiles(int start, int end) {
		return dao.getVideoFiles(start, end);
	}
	
	public void  loadVideoFilesByPage(DataPageUtil<VideoFile> dataPageUtil) {
		if (dataPageUtil != null) {
			dao.loadVideoFilesByPage(dataPageUtil);
			List<VideoFile> vfs = dataPageUtil.getResult();
			SimpleDateFormat formatter= new SimpleDateFormat("HH:mm:ss");
			formatter.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
			UserCache uc = CacheManager.getUserCache();
			for(VideoFile vf:vfs) {
				vf.setCreateUserName(uc.getUserName(vf.getCreateByUid()));
				vf.setDisPlayLen(formatter.format(vf.getPlayLen()));
				vf.setVideoSnapshotURL(ResourceURIReplacer.getVideoSnapshotURL(vf.getUid(), vf.getSnapshot()));
				vf.setVideoFileURL(ResourceURIReplacer.getVideoFileURL(vf.getUid(), vf.getFileExt()));
			}
	     }
	}

	/**
	 * Get VideoFile by primary key.
	 */
	@Override
	public VideoFile getVideoFile(String uid) {
		VideoFile v = dao.getVideoFile(uid);
		return v;
	}

}